<?php

/**
 * taxista actions.
 *
 * @package    KrazyTaxi
 * @subpackage taxista
 * @author     Your name here
 */
class taxistaActions extends sfActions
{
    public function executeIndex(sfWebRequest $request) {
        $this->signin = new sfGuardFormSignin();
        $this->gMap = new GMap();
        $this->gMap->setCenter(-33.56, -70.644);
        $this->gMap->setZoom(11);

        $c = new Criteria();
        $c->addJoin(PeticionPeer::IDRUTA,  DetallePeer::IDRUTA);
        $c->add(PeticionPeer::FECHAHORARUTA,  time() - 60*15 ,Criteria::GREATER_THAN );
        $c->add(DetallePeer::LINEADETALLE,1);
        $c->addJoin(DetallePeer::IDUBICACION, UbicacionPeer::IDUBICACION);
        
        $ubicaciones = UbicacionPeer::doSelect($c);
        
        foreach($ubicaciones as $ubicacion){
            
            $this->gMap->addMarker(new GMapMarker($ubicacion->getY() ,$ubicacion->getX()));
        }
    }

    public function executeShow(sfWebRequest $request) {
        $this->Chofer = ChoferPeer::retrieveByPk($request->getParameter('idchofer'));
        $this->forward404Unless($this->Chofer);
    }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new ChoferForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST));

    $this->form = new ChoferForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($Chofer = ChoferPeer::retrieveByPk($request->getParameter('idchofer')), sprintf('Object Chofer does not exist (%s).', $request->getParameter('idchofer')));
    $this->form = new ChoferForm($Chofer);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
    $this->forward404Unless($Chofer = ChoferPeer::retrieveByPk($request->getParameter('idchofer')), sprintf('Object Chofer does not exist (%s).', $request->getParameter('idchofer')));
    $this->form = new ChoferForm($Chofer);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($Chofer = ChoferPeer::retrieveByPk($request->getParameter('idchofer')), sprintf('Object Chofer does not exist (%s).', $request->getParameter('idchofer')));
    $Chofer->delete();

    $this->redirect('taxista/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $Chofer = $form->save();

      $this->redirect('taxista/edit?idchofer='.$Chofer->getIdchofer());
    }
  }
}
